/*--------------------------------------------------------------------------
 *
 * 	You may freely copy, distribute, and reuse the code in this example.
 * 	SHL Systemhouse disclaims any warranty of any kind, expressed or  
 *	implied, as to its fitness for any particular use.
 *
 *
 *	AppController
 *
 *	Inherits From:		NSObject
 *
 *	Conforms To:		None
 *
 *	Declared In:		AppController.h
 *
 *
 *------------------------------------------------------------------------*/
#import "AppController.h"
#import <eointerface/EOController.h>
#import <foundation/NSObject.h>
#import "ScrollViewExtensions.h"




@implementation AppController

/*--------------------------------------------------------------------------
 *	App Initializatoin
 *------------------------------------------------------------------------*/
- appDidInit: sender
{
	[eoController fetch];
	return self;
}
 
 
/*--------------------------------------------------------------------------
 *	Modifying Buffer Characteristics
 *------------------------------------------------------------------------*/
- setBuffering: sender
{
	switch ([sender selectedTag])
		{
		case 1:
			[eoController setSavesToObjectsAutomatically: YES];
			[eoController setSavesToDataSourceAutomatically: NO];
			break;
		case 2:
			[eoController setSavesToObjectsAutomatically: NO];
			[eoController setSavesToDataSourceAutomatically: YES];
			break;
		case 3:
			[eoController setSavesToObjectsAutomatically: NO];
			[eoController setSavesToDataSourceAutomatically: NO];
			break;
		case 0:
		default:
			[eoController setSavesToObjectsAutomatically: YES];
			[eoController setSavesToDataSourceAutomatically: YES];
			break;
		}
			
	return self;
}


/*--------------------------------------------------------------------------
 *	Cover Methods for EOController Actions
 *------------------------------------------------------------------------*/
- fetch: sender
{
	[console sprintf: "\nYou pressed the Fetch button...\n"];
	[objectButton setIcon: "empty"];
	[dataSourceButton setIcon: "empty"];
	[eoController fetch: sender];
	return self;
}


- insert: sender
{
	[console sprintf: "\nYou pressed the Insert button...\n"];
	[objectButton setIcon: "empty"];
	[dataSourceButton setIcon: "empty"];
	[eoController insert: sender];
	return self;
}


- delete: sender
{
	[console sprintf: "\nYou pressed the Delete button...\n"];
	[objectButton setIcon: "empty"];
	[dataSourceButton setIcon: "empty"];
	[eoController delete: sender];
	return self;
}


- saveToObjects: sender
{
	[console sprintf: "\nYou pressed the Save to Objects button...\n"];
	[objectButton setIcon: "empty"];
	[dataSourceButton setIcon: "empty"];
	[eoController saveToObjects: sender];
	return self;
}


- saveToDataSource: sender
{
	[console sprintf: "\nYou pressed the Save to Data Source button...\n"];
	[objectButton setIcon: "empty"];
	[dataSourceButton setIcon: "empty"];
	[eoController saveToDataSource: sender];
	return self;
}


- undo: sender
{
	[console sprintf: "\nYou pressed the Undo button...\n"];
	[objectButton setIcon: "empty"];
	[dataSourceButton setIcon: "empty"];
	[eoController undo: sender];
	return self;
}


/*--------------------------------------------------------------------------
 *	EOController Delegate Methods
 *------------------------------------------------------------------------*/
- (void)controller:(EOController *)controller didInsertObject:object
{
	[objectButton setIcon: "arrow"];
	[console sprintf: "DID INSERT TO OBJECTS\n"];
}


- (void)controller:(EOController *)controller didDeleteObject:object
{
	[objectButton setIcon: "arrow"];
	[console sprintf: "DID DELETE TO OBJECTS\n"];
}


- (void)controller:(EOController *)controller didSaveToObject:object
{
	[objectButton setIcon: "arrow"];
	[console sprintf: "DID SAVE TO OBJECTS\n"];
}


- (void)controllerDidSaveToDataSource:(EOController *)controller
{
	[dataSourceButton setIcon: "arrow"];
	[console sprintf: "DID SAVE TO DATA SOURCE\n"];
}


- (void)controller:(EOController *)controller
    didInsertObject:object
    inDataSource:dataSource
{
	[dataSourceButton setIcon: "arrow"];
	[console sprintf: "DID INSERT IN DATA SOURCE\n"];
}


- (void)controller:(EOController *)controller
    didDeleteObject:object
    inDataSource:dataSource
{
	[dataSourceButton setIcon: "arrow"];
	[console sprintf: "DID DELETE IN DATA SOURCE\n"];
}


- (void)controller:(EOController *)controller
    didUpdateObject:object
    inDataSource:dataSource
{
	[dataSourceButton setIcon: "arrow"];
	[console sprintf: "DID UPDATE IN DATA SOURCE\n"];
}


- (void)controller:(EOController *)controller 
	didRollbackDataSource:(id <EODataSources>)dataSource
{
	[dataSourceButton setIcon: "arrow"];
	[console sprintf: "DID ROLLBACK IN DATA SOURCE\n"];
}


@end
